使用jQuery进行多行字符串插入 [英] Multi-line string insert using jQuery

查看:100
本文介绍了使用jQuery进行多行字符串插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$("#addSelect").click(function() {
        $("#optionsForm").after("Hello world.");
} );

这样做。

$("#addSelect").click(function() {
        $("#optionsForm").after("<tr>
    <td><input type="text" class="optionField" value="Options" /></td>
    <td>
        <ul class="option">
            <li><select><option>Value..</option></select></li>
        </ul>
    </td>
</tr>");
} );

这样的事情没有。

在Chrome中,我收到错误意外令牌ILLEGAL 。谷歌搜索后,我发现我的小脑对javascript和多行知之甚少。所以我在每一行的末尾添加了'\'。然而,我现在收到错误意外的标识符

In Chrome, I get the error "Unexpected token ILLEGAL". After Googling I've discovered my teeny brain doesn't know much about javascript and multi-lines. So I added '\' to then end of each line. Yet, I now get the error "Unexpected identifier".

我希望这不会像我做的那样困难:)

I'd like this to not be as difficult as I'm making it :)

推荐答案

将属性的所有双引号更改为单引号。

Change all the double quotes for the attributes to single quotes.

$("#addSelect").click(function() { 
        $("#optionsForm").after("<tr> \
    <td><input type='text' class='optionField' value='Options' /></td> \
    <td> \
        <ul class='option'> \
            <li><select><option>Value..</option></select></li> \
        </ul> \
    </td> \
</tr>"); 
} ); 

这篇关于使用jQuery进行多行字符串插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆