廣豐視角
關(guān)注互聯(lián)網(wǎng),關(guān)注技術(shù)開(kāi)發(fā),透析與分享移動(dòng)互聯(lián)網(wǎng)行業(yè)最新動(dòng)態(tài)jQuery設(shè)置和獲取HTML、文本和值
時(shí)間:2019-02-18 18:22:31 閱讀:85918次 分類(lèi):APP開(kāi)發(fā)
<script type="text/javascript">
//<![CDATA[
$(function(){
//獲取<p>元素的HTML代碼
$("input:eq(0)").click(function(){
alert( $("p").html() );
});
//獲取<p>元素的文本
$("input:eq(1)").click(function(){
alert( $("p").text() );
});
//設(shè)置<p>元素的HTML代碼
$("input:eq(2)").click(function(){
$("p").html("<strong>你最喜歡的水果是?</strong>");
});
//設(shè)置<p>元素的文本
$("input:eq(3)").click(function(){
$("p").text("你最喜歡的水果是?");
});
//設(shè)置<p>元素的文本
$("input:eq(4)").click(function(){
$("p").text("<strong>你最喜歡的水果是?</strong>");
});
//獲取按鈕的value值
$("input:eq(5)").click(function(){
alert( $(this).val() );
});
//設(shè)置按鈕的value值
$("input:eq(6)").click(function(){
$(this).val("我被點(diǎn)擊了!");
});
});
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
$(function(){
$("#address").focus(function(){ // 地址框獲得鼠標(biāo)焦點(diǎn)
var txt_value = $(this).val(); // 得到當(dāng)前文本框的值
if(txt_value=="請(qǐng)輸入郵箱地址"){
$(this).val(""); // 如果符合條件,則清空文本框內(nèi)容
}
});
$("#address").blur(function(){ // 地址框失去鼠標(biāo)焦點(diǎn)
var txt_value = $(this).val(); // 得到當(dāng)前文本框的值
if(txt_value==""){
$(this).val("請(qǐng)輸入郵箱地址");// 如果符合條件,則設(shè)置內(nèi)容
}
})
$("#password").focus(function(){
var txt_value = $(this).val();
if(txt_value=="請(qǐng)輸入郵箱密碼"){
$(this).val("");
}
});
$("#password").blur(function(){
var txt_value = $(this).val();
if(txt_value==""){
$(this).val("請(qǐng)輸入郵箱密碼");
}
})
});
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
$(function(){
$("#address").focus(function(){ // 地址框獲得鼠標(biāo)焦點(diǎn)
var txt_value = $(this).val(); // 得到當(dāng)前文本框的值
if(txt_value==this.defaultValue){
$(this).val(""); // 如果符合條件,則清空文本框內(nèi)容
}
});
$("#address").blur(function(){ // 地址框失去鼠標(biāo)焦點(diǎn)
var txt_value = $(this).val(); // 得到當(dāng)前文本框的值
if(txt_value==""){
$(this).val(this.defaultValue);// 如果符合條件,則設(shè)置內(nèi)容
}
})
$("#password").focus(function(){
var txt_value = $(this).val();
if(txt_value==this.defaultValue){
$(this).val("");
}
});
$("#password").blur(function(){
var txt_value = $(this).val();
if(txt_value==""){
$(this).val(this.defaultValue);
}
})
});
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
$(function(){
//設(shè)置單選下拉框選中
$("input:eq(0)").click(function(){
$("#single").val("2");
});
//設(shè)置多選下拉框選中
$("input:eq(1)").click(function(){
$("#multiple").val(["選擇2號(hào)", "選擇3號(hào)"]);
});
//設(shè)置單選框和多選框選中
$("input:eq(2)").click(function(){
$(":checkbox").val(["check2","check3"]);
$(":radio").val(["radio2"]);
});
});
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
$(function(){
//設(shè)置單選下拉框選中
$("input:eq(0)").click(function(){
$("#single option").removeAttr("selected"); //移除屬性selected
$("#single option:eq(1)").attr("selected",true); //設(shè)置屬性selected
});
//設(shè)置多選下拉框選中
$("input:eq(1)").click(function(){
$("#multiple option").removeAttr("selected"); //移除屬性selected
$("#multiple option:eq(2)").attr("selected",true);//設(shè)置屬性selected
$("#multiple option:eq(3)").attr("selected",true);//設(shè)置屬性selected
});
//設(shè)置單選框和多選框選中
$("input:eq(2)").click(function(){
$(":checkbox").removeAttr("checked"); //移除屬性checked
$(":radio").removeAttr("checked"); //移除屬性checked
$(":checkbox[value=check2]").attr("checked",true);//設(shè)置屬性checked
$("[value=check3]:checkbox").attr("checked",true);//設(shè)置屬性checked
$("[value=radio2]:radio").attr("checked",true);//設(shè)置屬性checked
});
});
//]]>
</script>
:checkbox 表示屬性為checkbox
蕪湖廣豐軟件有限公司(原中江網(wǎng)絡(luò)),成立于2005年,經(jīng)過(guò)10多年定制開(kāi)發(fā)經(jīng)驗(yàn),積累了大量技術(shù)儲(chǔ)備和定制開(kāi)發(fā)經(jīng)驗(yàn),是一家集軟件研發(fā)、互聯(lián)網(wǎng)應(yīng)用為一體的綜合信息技術(shù)服務(wù)提供商。公司擁有核心的策劃團(tuán)隊(duì)和專(zhuān)業(yè)的技術(shù)研發(fā)團(tuán)隊(duì),致力于采用領(lǐng)先的信息技術(shù),長(zhǎng)期為涉及智慧園區(qū)/廠(chǎng)區(qū)/校園領(lǐng)域的各個(gè)企業(yè)提供快速、高效、安全的信息技術(shù)支持。公司立足智慧園區(qū)和智慧教育行業(yè),通過(guò)軟硬件的研發(fā)和互聯(lián)網(wǎng)應(yīng)用,疏通各企業(yè)間“端到端”的信息傳輸,靈活滿(mǎn)足智慧園區(qū)和智慧教育企業(yè)間不同用戶(hù)的需求,為其提供完善的信息化解決方案。
園區(qū)管理系統(tǒng),提供智慧園區(qū)綜合管理系統(tǒng),智慧園區(qū)設(shè)計(jì)方案咨詢(xún),智慧園區(qū)管理系統(tǒng)、...