第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

jquey動(dòng)態(tài)創(chuàng)建dom,綁定函數(shù),帶有字符參數(shù)的問(wèn)題?

jquey動(dòng)態(tài)創(chuàng)建dom,綁定函數(shù),帶有字符參數(shù)的問(wèn)題?

慕虎7371278 2018-12-27 22:19:20
""<li><input type='button' value='確定' class='verifition' onclick='cancelDouble("+this.index+","+this.title+")'></li>";<li><input type='button' value='確定' class='verifition' data-cid="+this.title+" onclick='cancelDouble("+this.index+")'></li>";本來(lái)是上面那樣的,但是html編譯出來(lái),說(shuō)this.title對(duì)應(yīng)的字符是is not undifend,所有就只能曲線(xiàn)救國(guó)了,正常下html中的函數(shù)字符串是要有引號(hào)的,數(shù)字可不用,但是jquery生成的實(shí)在是不知道在哪里加了,
查看完整描述

1 回答

?
HUH函數(shù)

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超4個(gè)贊

報(bào)錯(cuò)誤的原因是,你拼接html的時(shí)候,把title作為一個(gè)變量傳進(jìn)去了,而不是一個(gè)字符串。


而如果你使用字符串冒號(hào)包裹title的話(huà)又會(huì)和html的冒號(hào)沖突,因此比較好的方式是,onclick=cancelDouble('+item.index+',"'+item.title+'") 的時(shí)候,onclick=后面的方法不要用引號(hào)包裹,然后參數(shù)就可以友好的拼接字符串,把參數(shù)當(dāng)成字符串處理而不是變量


https://img1.sycdn.imooc.com//5c4d626700015a1103500081.jpg


    var arr = [

        { index: 0, title: 'title0' },

        { index: 1, title: 'title1' },

        { index: 2, title: 'title2' },

        { index: 3, title: 'title3' },

        { index: 4, title: 'title4' },

    ];

    var htm = '';

    arr.forEach(function(item) {

        htm+='<li><input type="button" value="確定" class="verifition" onclick=cancelDouble('+item.index+',"'+item.title+'")></li>';

    });

    $("body").html(htm);

    function cancelDouble(index,title){

        console.log(index,title)

    }


查看完整回答
反對(duì) 回復(fù) 2019-01-27
  • 1 回答
  • 0 關(guān)注
  • 454 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)