3

我知道这是一个非常简单的问题,我想知道如何将 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>

知道怎么做吗?

请注意,这有 jquery 移动结构

4

3 回答 3

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());
于 2013-07-19T07:24:31.360 回答
0

当您使用 jquery 时,您可以获得 html 作为

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

只需传递inputHtml给任何功能

于 2013-07-19T07:23:59.797 回答
0

当您使用 jQuery mobile 时,您可以尝试使用

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

yourFunction(htmlBlock);
于 2013-07-19T07:26:16.847 回答