今天做jquery遇到的一些问题汇总
1.对select下拉框进行宽度控制
<select name="" style="width:72px " >
2.对于表格th和td列宽的控制
一定要在th和td标签后面都给添加上 width属性,或者再css里面定义,否则表格这种奇葩的渣渣不按常规出牌,全部平均化列宽~~
3.jquery遍历form下的元素,并返回它的id
两种办法:
1).通过map()
$('#form1 *').map(function() {
return this.id;
}).get() )
2)通过each()
$('#form1 :hidden').each(function ()
{
//alert($(this).attr('id'));
var x = $(this).attr('id');
$('#' + x).val("");
}
);
//显示所有子节点
/*
$('#form1 :hidden').each(function(){
alert($(this).attr('id')+":"+$(this).val());
});
*/
$('#flag').val("update");
//alert($("select[name=align"+ index+"]").val());
//alert($('#align' + index).find("option:selected").text());
$('#align').val($("select[name=align" + index + "]").val());
$('#isNumeric').val($("select[name=isNumeric" + index + "]").val());
$('#form1 :hidden').each(function ()
{
//alert($(this).attr('id'));
var x = $(this).attr('id');
valInputNameByIndex(x, index);
}
);
$('#form1 *').each(function ()
{
alert($(this).attr('id') + ":" + $(this).val());
}
);
4.jquery选择器中含有变量的情况:
$('#' + inputName).val();
function valInputNameByIndex(inputName, index)
{
// alert($("'#" + inputName +"'").val();
//alert($('#' + inputName).val());
var x = $('#' + inputName).val();
if (x == "")
{
return $('#' + inputName).val($("input[name=" + inputName + index + "]").val());
}
else
{
return x;
}
}
5.jquery 超链接点击后提交表单
<a href="#" id="toUpdatePdf">
$('#toUpdatePdf').click(function ()
{
$('#flag').val('update');
//alert($('#flag').val());
$('#form2').submit();
}
);
6.jquery根据name拿到值
$('#seqNo').val($("input[name=seqNo"+ index+"]").val()); //index是前台调用js的时候传入的
7.完整js
<script type="text/javascript">
function update(index){
//alert($('#form1 *').map(function() {return this.id;}).get() )
$('#form1 :hidden').each(function ()
{
//alert($(this).attr('id'));
var x = $(this).attr('id');
$('#' + x).val("");
}
);
//显示所有子节点
/*
$('#form1 :hidden').each(function(){
alert($(this).attr('id')+":"+$(this).val());
});
*/
$('#flag').val("update");
//alert($("select[name=align"+ index+"]").val());
//alert($('#align' + index).find("option:selected").text());
$('#align').val($("select[name=align" + index + "]").val());
$('#isNumeric').val($("select[name=isNumeric" + index + "]").val());
$('#form1 :hidden').each(function ()
{
//alert($(this).attr('id'));
var x = $(this).attr('id');
valInputNameByIndex(x, index);
}
);
$('#form1 *').each(function ()
{
alert($(this).attr('id') + ":" + $(this).val());
}
);
/*
$(":hidden").each(function(){
alert($(this).attr('id'));
});
*/
// valInputNameByIndex("seqNo",index);
// alert($('#seqNo').val());
//序号
//valInputNameByIndex("seqNo",index);
//$('#seqNo').val($("input[name=seqNo"+ index+"]").val());
//字段名
//$('#fieldName').val($("input[name=fieldName"+ index+"]").val());
//描述
//$('#seqNo').val($("input[name=seqNo"+ index+"]").val());
//描述
//$('#seqNo').val($("input[name=seqNo"+ index+"]").val());
//宽度
//$('#seqNo').val($("input[name=seqNo"+ index+"]").val());
//对齐方式
//$('#seqNo').val($("input[name=seqNo"+ index+"]").val());
//数字列
//$('#seqNo').val($("input[name=seqNo"+ index+"]").val());
//小数位数
//$('#seqNo').val($("input[name=seqNo"+ index+"]").val());
//$('#seqNo').val($("input[name=seqNo"+ index+"]").val());
//$('#seqNo').val($("input[name=seqNo"+ index+"]").val());
// var y = $("#"+inputName).val();
//alert($("input[name="+inputName+"]").val());
//var inputValue = ($("#" + inputName).val());
//alert(inputValue);
//$('#seqNo').val($("'"+inputName+"'").val());
//alert($('#seqNo').val());
}
function valInputNameByIndex(inputName, index)
{
// alert($("'#" + inputName +"'").val();
//alert($('#' + inputName).val());
var x = $('#' + inputName).val();
if (x == "")
{
return $('#' + inputName).val($("input[name=" + inputName + index + "]").val());
}
else
{
return x;
}
}
/*
$('#update').click(function () {
update('${index}');
//$('#flag').val('update');
//alert($('#flag').val());
//$('#form1').submit();
});
*/
$('#toUpdatePdf').click(function ()
{
$('#flag').val('update');
//alert($('#flag').val());
$('#form2').submit();
}
);
</script>
8.html部分源码
<form action="" method="post" id="form1" name="form1"> <input type="hidden" id="seqNo" name="seqNo" value=""/> <input type="hidden" id="fieldName" name="fieldName" value=""/> <input type="hidden" id="descMsg" name="descMsg" value=""/> <input type="hidden" id="width" name="width" value=""/> <input type="hidden" id="align" name="align" value=""/> <input type="hidden" id="isNumeric" name="isNumeric" value=""/> <input type="hidden" id="deciLength" name="deciLength" value=""/> <input type="hidden" id="flag" name="flag" value=""/> </form>
落雨
qq 394263788
2013年6月6日18:03:48


浙公网安备 33010602011771号