在追加函数缺少参数列表时给出错误

时间:2018-03-14 09:29:36

标签: jquery

当我尝试运行代码时出现以下错误我知道错误是在追加函数中我不知道如何处理转义字符

{{1}}

2 个答案:

答案 0 :(得分:1)

您必须转义代码中的''

像这样:oninput="this.className=\'\'"

请看下面的解决方案:



var usertype = "individual"
function check() {
  if (usertype == null) {
    alert('please select user type');
  } else {
    $('#registerusers').hide();
    if (usertype == 'individual') {
      $('#agent').html();
      $('#vendor').html();
      $('#service').html();
      $('#' + usertype).append('<div class="tab">Name: <p><input placeholder="First name..." oninput="this.className=\'\'"></p><p><input placeholder="Last name..." oninput="this.className=\'\'"></p> </div> <div class="tab">Contact Info: <p><input placeholder="E-mail..." oninput="this.className=\'\'"></p> <p><input placeholder="Phone..." oninput="this.className=\'\'"></p> </div> <div class="tab">Birthday: <p><input placeholder="dd" oninput="this.className=\'\'"></p> <p><input placeholder="mm" oninput="this.className="></p> <p><input placeholder="yyyy" oninput="this.className=\'\'"></p> </div> <div class="tab">Login Info: <p><input placeholder="Username..." oninput="this.className=\'\'"></p> <p><input placeholder="Password..." oninput="this.className=\'\'"></p> </div> <div style="overflow:auto;"> <div style="float:right;"> <button type="button" id="prevBtn" onclick="nextPrev(-1)">Previous</button> <button type="button" id="nextBtn" onclick="nextPrev(1)">Next</button> </div> </div> <!-- Circles which indicates the steps of the form: --> <div style="text-align:center;margin-top:40px;"> <span class="step"></span> <span class="step"></span> <span class="step"></span> <span class="step"></span> </div> ');
      $('#' + usertype).removeClass('hid');
    } else if (usertype == 'agent') {
      $('#individual').html();
      $('#vendor').html();
      $('#service').html();

      $('#' + usertype).html('<h2> as</h2>');
      $('#' + usertype).removeClass('hid');
    }
    alert(usertype);
  }

}

check()
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="individual"></div>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

试试这个:

function check()
{
    if(usertype==null)
    {
        alert('please select user type');
    }
    else
    {
        $('#registerusers').hide();
        if(usertype=='individual')
        {   
            $('#agent').html();
            $('#vendor').html();
            $('#service').html();
            $('#'+usertype).append('\
                <div class="tab">\
                    Name: <p><input placeholder="First name..." oninput="this.className = '+""+'"></p>\
                    <p><input placeholder="Last name..." oninput="this.className = '+""+'"></p> \
                </div> \
                <div class="tab">\
                    Contact Info: <p><input placeholder="E-mail..." oninput="this.className = '+""+'"></p> \
                    <p><input placeholder="Phone..." oninput="this.className = '+""+'"></p> \
                </div> \
                <div class="tab">\
                    Birthday: <p><input placeholder="dd" oninput="this.className = '+""+'"></p> \
                    <p><input placeholder="mm" oninput="this.className = '+""+'"></p> \
                    <p><input placeholder="yyyy" oninput="this.className = '+""+'"></p>\ 
                </div> \
                <div class="tab">\
                    Login Info: <p><input placeholder="Username..." oninput="this.className = '+""+'"></p> \
                    <p><input placeholder="Password..." oninput="this.className = '+""+'"></p> \
                </div> \
                <div style="overflow:auto;"> \
                    <div style="float:right;"> \
                        <button type="button" id="prevBtn" onclick="nextPrev(-1)">Previous</button> \
                        <button type="button" id="nextBtn" onclick="nextPrev(1)">Next</button> \
                    </div> \
                </div> <!-- Circles which indicates the steps of the form: --> \
                <div style="text-align:center;margin-top:40px;"> \
                    <span class="step"></span> \
                    <span class="step"></span> \
                    <span class="step"></span> \
                    <span class="step"></span> \
                </div> \
            ');
            $('#'+usertype).removeClass('hid');
        }
        else if(usertype=='agent')
        {
            $('#individual').html();
            $('#vendor').html();
            $('#service').html();

            $('#'+usertype).html('<h2> as</h2>');
            $('#'+usertype).removeClass('hid');
        }



        alert(usertype);
    }

}