Recently, when using the Layui front-end framework, I often encounter some initialization things when using radio buttons, drop-down menu select, checkbox and other controls.
Sometimes you will find that the code you dynamically append is either not displayed, or the default selection is initing problems.
The above situations were tested:
The first case: The solution to the dynamic append() html code without displaying space:
Add to
();//Re-render It can solve various situations where there is no display
The second case: Dynamically setting the default selected state has no effect solution:
It is divided into two situations:
(1) Under the html page code (not in the layer initialization framework, that is, not initialized in ([], function(){ }))
Take the default selection of checkbox init as an example:
$('.xxx').attr("checked", true); //Note that the use of attr() is used here(); //Re-render the display effect
(2) Initialization in (); This situation will usually occur after calling the API interface error, otherwise checkbox will change the state.
(['form','layer'],function(){ var form = layer = === undefined ? : , $ = ; if ($('.xxxx').attr("checked") === "checked") { //Judge whether to select $('.xxxx').prop("checked", true); //Settings are selected. Note that the use of prop() is used here. If attr() is used here, it will be invalid. } else { $('.xxxx').prop("checked", false); } (); //Re-render});
The above example of the dynamic setting of checbox selection status of the layui is all the content I share with you. I hope you can give you a reference and I hope you can support me more.