jquery輸出html代碼的方法:1、直接輸出標(biāo)簽元素,代碼為【var form1 = "<form id=\\"myform\\" method=\\"post\\" >"】;2、輸出帶變量的標(biāo)簽元素,代碼為【var country =....】。
臨西網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,臨西網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為臨西1000+提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢,請找那個售后服務(wù)好的臨西做網(wǎng)站的公司定做!
jquery輸出html代碼的方法:
形式一:直接輸出標(biāo)簽元素
1.采用轉(zhuǎn)義符號
var form1 = "<form id=\\"myform\\" method=\\"post\\" >" +"<input type=\\"text\\" name=\\"uname\\" style=\\"height:20px;width:100%;\\" />" +"<input type=\\"password\\" name=\\"pwd\\" style=\\"height:20px;width:100%;\\" />" +"</form>";
2.采用單引號
var form2 = \'<form id="myform" method="post" >\' +\'<input type="text" name="uname" style="height:20px;width:100%;" />\' +\'<input type="password" name="pwd" style="height:20px;width:100%;" />\' +\'</form>\';
3.采用es6的模板字符量(不過我喜歡用模板字符串來稱呼這個。。。)
就是在前后都加上了一個( ` ),它中間就寫你要輸出的東西,寫標(biāo)簽就輸出標(biāo)簽,寫\\n就表示換行,寫變量的話是不會輸出變量代表的值,而是把變量的名字給輸出來。比如說變量country的值為“中國”,那么它不會輸出中國這個值,而是country變量名,要輸出值的話請看 形式二。
var form3 = `<form id="myform" method="post"> <input type="text" name="uname" style="height:20px;width:100%;" /> <input type="password" name="pwd" style="height:20px;width:100%;" /> </form>`
形式二:輸出帶變量的標(biāo)簽元素
1.采用轉(zhuǎn)義符號
var country = "中國"; var table = "<table border=\\"1\\" style=\\"width:100%;\\">"; table += "<caption>國家信息列表</caption>"; table += "<thead><tr><th>ID</th><th>Name</th></tr></thead>"; table += "<tbody><tr><td>1</td><td>"+country+"</td></tr></tbody>"; table += "</table>";
2.采用單引號
var country = "中國"; var table = \'<table border="1" style="width:100%;">\'; table += \'<caption>國家信息列表</caption>\'; table += \'<thead><tr><th>ID</th><th>Name</th></tr></thead>\'; table += \'<tbody><tr><td>1</td><td>"\'+country+\'"</td></tr></tbody>\'; table += \'</table>\';
3.采用es6的模板字符量(不過我喜歡用模板字符串來稱呼這個。。。)
輸出變量的值,比如上面說到的country=“中國”,那么要怎么才可以輸出中國這個值呢?
其實可以用占位符來代表${ }
,括號中間的部分就寫上你要輸出變量所代表的變量名稱。
var country = "中國"; var table = `<table border="1" style="width:100%;">`; table += `<caption>國家信息列表</caption>`; table += `<thead><tr><th>ID</th><th>Nane</th></tr></thead>`; table += `<tbody><tr><td>1</td><td>${country}</td></tr></tbody>`; table += `</table>`;
名稱欄目:jquery怎么輸出html代碼
本文網(wǎng)址:http://m.rwnh.cn/article2/cpsiic.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供Google、響應(yīng)式網(wǎng)站、微信小程序、企業(yè)網(wǎng)站制作、網(wǎng)站建設(shè)、自適應(yīng)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)