本文主要是介绍JQuery设置checkbox的值,取checkbox的值,设置radio的值,取radio的值,设置下拉选select的值,取select的值,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、复选框设置参数
html代码如下:
<div class="flsm_btns">
<input type="hidden" name="agreeFlagValue" id="agreeFlagValue"
value="${copyRight.agreeFlag}"/>
<input type="checkbox" name="agreeFlag" id="agreeFlag" />
<span>
<a id="low-declare" target="_blank" href="${pageContext.request.contextPath}/web/law">
我已阅读酷漫网相关法律声明
</a>
</span>
</div>
$(function(){
var agreeFlagValue = $("#agreeFlagValue").attr("value");
if(agreeFlagValue != "" && agreeFlagValue == "1") {
$("#agreeFlag").attr("checked",true);
} else {
$("#agreeFlag").attr("checked",false);
}
});
获取checkbox的值,并判断
console.log(document.getElementById("agreeFlag").checked);
var agreeFlag = (document.getElementById("agreeFlag").checked == true) ? 1 : 0;
if(agreeFlag == 0) {
lock = false;
alert("对不起,您得先同意酷漫网相关法律声明才可以发布版权信息!");
$("#low-declare").css("color","red");
} else {
lock = true;
$("#low-declare").css("color","#2d3e53");
}
二、设置radio的参数值
html代码如下:
<div class="upl">
<div class="uplena">信息有效期限:</div>
<div class="upricon mt10">
<input type="hidden" name="termOfValidityValue" id="termOfValidityValue"
value="${copyRight.termOfValidity}"/>
<div class="checkbox">
<input type="radio" name="termOfValidity" value="14天"/><span>14天</span>
</div>
<div class="checkbox">
<input type="radio" name="termOfValidity" value="一个月"/><span>一个月</span>
</div>
<div class="checkbox">
<input type="radio" name="termOfValidity" value="无限期"/><span>无限期</span>
</div>
</div>
</div>
$(function(){
var termOfValidityValue = $("#termOfValidityValue").attr("value");
if(termOfValidityValue != "") {
$("input[name='termOfValidity'][value='" + termOfValidityValue + "']").attr("checked","checked");
} else {
$("input[name='termOfValidity'][value!='" + termOfValidityValue + "']").removeAttr("checked");
}
});
获取radio的选中值:
/* 本信息有效期限 */
var termOfValidity = $('input[name="termOfValidity"]:checked').val();
三、获取selected的值
设置选中状态:
$("#filter_item_con select option:first").attr("selected","selected");
获取选中值:
var selectedCity = $("#filter_item_con #city option:selected").attr("value");
这篇关于JQuery设置checkbox的值,取checkbox的值,设置radio的值,取radio的值,设置下拉选select的值,取select的值的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!