2013-07-19 85 views
3

我知道這是一個非常簡單的問題,我想知道如何將html塊作爲參數傳遞給函數,並在頁面加載時立即調用該函數。傳遞html塊作爲參數

<body> 
<section data-role="page" data-theme="ams"> 
    <section data-role="header" id="content"> 
     <h1>header ssssssssssssssssssssssssssssss sssssssssssssssssssssss ssssssssssssssssssssssssss ssssssssssssssss ssssssssssss</h1> 

    </section> 
    <section data-role="conents" > 
     <p>loruim epsum haha&nbsp;</p>\n<p>hehe told u&nbsp;</p>\n<ol class=\"starpasspro-upper-alpha_ol\">\n<li>gasdfg</li>\n<li>sdfffasd</li>\n<li>asdfffasdf</li>\n<li>asdfasdfasdfasd</li>\n</ol>\n\n<table class=\"table_with_header lsm-tableclass-styles\">\n<tbody>\n<tr>\n<td class=\"lsm_table_heading_1\">Description</td>\n<td class=\"lsm_table_heading_1\">Amount</td>\n</tr>\n<tr>\n<td>Gross salary</td>\n<td>&nbsp;xxxx</td>\n</tr>\n<tr>\n<td>Less: income tax (£35,000 x 25%)</td>\n<td>&nbsp;xxxx</td>\n</tr>\n<tr>\n<td>Less: social security tax (£50,000 x 9%)</td>\n<td>&nbsp;xxxx</td>\n</tr>\n<tr>\n<td>Net earnings</td>\n<td>&nbsp;xxxx</td>\n</tr>\n<tr>\n<td>Employer’s contribution on social security<br>(£50,000 x10.5%)</td>\n<td>&nbsp;xxxx</td>\n</tr>\n</tbody>\n</table>\n\n 
     <p><span data-lscp-resource-mimetype=\"image/png\" data-lscp-resource-id=\"51e8db617607942807000032\"></span></p> 


    </section> 
    <section data-role="footer"> 
     <p>footer</p> 

    </section> 
</section> 

,我想下面的HTML塊傳遞給我的函數作爲參數

<p>loruim epsum haha&nbsp;</p>\n<p>hehe told u&nbsp;</p>\n<ol class=\"starpasspro-upper-alpha_ol\">\n<li>gasdfg</li>\n<li>sdfffasd</li>\n<li>asdfffasdf</li>\n<li>asdfasdfasdfasd</li>\n</ol>\n\n<table class=\"table_with_header lsm-tableclass-styles\">\n<tbody>\n<tr>\n<td class=\"lsm_table_heading_1\">Description</td>\n<td class=\"lsm_table_heading_1\">Amount</td>\n</tr>\n<tr>\n<td>Gross salary</td>\n<td>&nbsp;xxxx</td>\n</tr>\n<tr>\n<td>Less: income tax (£35,000 x 25%)</td>\n<td>&nbsp;xxxx</td>\n</tr>\n<tr>\n<td>Less: social security tax (£50,000 x 9%)</td>\n<td>&nbsp;xxxx</td>\n</tr>\n<tr>\n<td>Net earnings</td>\n<td>&nbsp;xxxx</td>\n</tr>\n<tr>\n<td>Employer’s contribution on social security<br>(£50,000 x10.5%)</td>\n<td>&nbsp;xxxx</td>\n</tr>\n</tbody>\n</table>\n\n 
     <p><span data-lscp-resource-mimetype=\"image/png\" data-lscp-resource-id=\"51e8db617607942807000032\"></span></p> 

任何想法HOWTO做到這一點?

注意到這有jQuery Mobile的結構

+0

你可以發佈你的功能嗎?或版本。 – Toiletduck

+0

@ChamZ,我認爲,你可以綁定代碼中的部分,即'$ mycodeblock ='

loruim epsum haha​​&...「>

',然後將這個$ mycodeblock作爲參數發送給你的函數,這可能對你有幫助。 –

回答

0

當你正在使用jQuery,你可以得到HTML作爲

var inputHtml = $("section[data-role='conents']").html(); 

只是通過inputHtml到任何功能

1
function yourFunction(htmlBlock){ 
    // your code 
} 

// call function and pass Jquery object 
yourFunction($('section[data-role="conents"]')); 
// call function and pass html code of object 
yourFunction($('section[data-role="conents"]').html()); 
0

因爲你是使用jQuery手機,你可以嘗試使用

var htmlBlock = $('section[data-role="conents"]').html(); 

yourFunction(htmlBlock);