日期:2014-05-16  浏览次数:20357 次

JSP --常用功能--
$("#submit").click(function(){
    	
	});

?JSP --常用功能--

?

一、单选 Radio 默认选中

<TR class="tab">
<TD colspan="4">
<input type="text" name="goround" id="goround" value="${goround}">
<input type="radio" name="gr" id="gr1" value="1" onclick="funsGr('1')">&nbsp;&nbsp;单&nbsp;&nbsp;程&nbsp;&nbsp;&nbsp;&nbsp;	  	
<input type="radio" name="gr" id="gr2" value="2" onclick="funsGr('2')"/>&nbsp;&nbsp;来&nbsp;&nbsp;回&nbsp;&nbsp;程&nbsp;&nbsp;</TD>
</TR>

?? js:默认选中:

if($('#goround').val()==''){
$('#goround').val('1');
$("#gr1").attr("checked",true); 
}

?

二、DIV:

<div style="margin-top:30px;"></div>
<div id="golabel" style="margin-bottom:1px;display:none">去程:</div>
<div id="norecord" style="margin-bottom:1px;display:none">系统搜索不到该数据,请重新查询!</div>
<div id="maingrid" style="margin-top:1px;"></div>

<div style="margin-top:30px;"></div>
<div id="goroundlabel" style="margin-bottom:1px;display:none">回程:</div>
<div id="goroundgrid" style="margin-top:1px;"></div>

?

?==============================================================================

一、获取表单selected选中文本内容
var mykindtxt=$("#kind  option:selected").text();

二、获取单选按钮的值
var valradio = $("input[@type=radio][@checked]").val();

三、获取复选框的值
var checkboxval = $("#checkbox_id").attr("value");

四、获取下拉列表选中的值
var selectval = $('#select_id').val();

五、多选框checkbox
if($("#chk_id").attr('checked')==undefined) //判断是否已经选中

六、单选组radio
设置value=10的单选按钮为当前选中项:
$("input[@type=radio]").attr("checked",'10');

七、下拉框select
设置value=test的项目为当前选中项:
$("#select_id").attr("value",'test');

添加下拉框的option:
$("<option value='test'>test</option><option value='test2'>test2</option>").appendTo("#select_id")

清空下拉框:
$("#select_id").empty();

八、下拉框select JSP:
<select id="selectId"><option value="biuuu_s1">s1</option>
<option value="biuuu_s2">s2</option>
<option value="biuuu_s3">s3</option>
<option value="biuuu_s4">s4</option>
</select>

js:
var selectedObj = $("#selectId option:selected");//获取当前selected的值
var selected = selectedObj.get(0).value;

九、checkbox组:
<input type="checkbox" name="checkboxId" value="biuuu_c1" />c1
<input type="checkbox" name="checkboxId" value="biuuu_c2" />c2
<input type="checkbox" name="checkboxId" value="biuuu_c3" />c3
<input type="checkbox" name="checkboxId" value="biuuu_c4" />c4
<input type="button" id="cButtonId" value="获取checkbox值" /><span id="cResult"></span>
js:
var Check = '';
var checkedObj = $("[name='checkboxId'][@checked]");//获取当前checked的value值 如果选中多个则循环
checkedObj.each(function(){
 var isCheck = this.value;Check += isCheck;
});

十、radio组:
<input type="radio" name="radioId" value="biuuu_r1" />r1
<input type="radio" name="radioId" value="biuuu_r2" />r2
<input type="radio" name="radioId" value="biuuu_r3" />r3
<input type="button" id="rButtonId" value="获取radio值" /><span id="rResult"></span>
js:
var radioObj = $("[name='radioId'][@checked]");//获取当前checked的value值
var radio = radioObj.get(0).value;


十一、

?

?==============================================================================

一、绑定按钮的js方法:

?

?==============================================================================