1.页面加载执行语句
jQuery(document).ready(function ($) {
// $(".tabs").tabs();
});
2. ajax 交互并渲染页面的combobox 控件
function foo(product_id)
{
$.ajax({
type: "GET",
url: "getFoo?productname="+product_id,
dataType: "json",
//async:false,//取消异步请求
success: function(data,textStatus){
// display
var bnSelect = document.getElementById("mycombobox");
for ( var i=bnSelect.options.length-1; i>-1; i-- )
{
bnSelect[i] = null;
}
if(data.length > 0) {
$("#mycombobox").show();
for(i=0;i<data.length;i++)
{
bnSelect.options[i] = new Option();
bnSelect.options[i].text = data[i].label;
bnSelect.options[i].value = data[i].value;
}
bnSelect.options[0].selected="selected";// default select the first one
}
}// end of success....func
}) //end of ajax
}//end of func
3. 隐藏/显示 div 或 tr td 控件
$('#myid').css("display", "none");//hide this.
$('#myid').css("display", "");//show this.
4. set requried 域, remove required
var all_row=$("tr[name^='tr_']")
all_row.prop('required',true);
all_locale_row.removeAttr('required'); // remove required
遇到一个异常报“An invalid form control with name=xxx is not focusable” ,通常是因为设置了required 域后的控件被隐藏的缘故,不过在实际中,遇到该异常提示的name与实际出问题的控件名字不一致的情况……不晓得为什么
5. set text
对<p>:
var msg = "Must select target locales !";
$('#my_p').text(msg);
6. get value for multi-select
var targeted = $('#selectTarget').val();
if (targeted == null)
{
// do something
}
for(var i =0;i<targeted.length;i++)
{
var locale_r=$('#tr_'+targeted[i]);
locale_r.css("display", "");//show this.
locale_r.prop('required',true);
}
To be continued....