Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery:编辑从$.get返回的数据字符串_Javascript_Jquery - Fatal编程技术网

Javascript jQuery:编辑从$.get返回的数据字符串

Javascript jQuery:编辑从$.get返回的数据字符串,javascript,jquery,Javascript,Jquery,我想编辑从$返回的数据。获取。我一直在研究如何应用新创建的inputname,我认为问题在于$(数据) 试一试 什么是数据?它应该是什么,你确定你得到了你想要的吗?把它记录在哪里。 id = '12'; $.get('/page.php?id='+id, function(data) { // split input name by hyphen m = $(data).find('input').attr('name').split('-');

我想编辑从
$返回的
数据
。获取
。我一直在研究如何应用新创建的
inputname
,我认为问题在于
$(数据)

试一试


什么是
数据
?它应该是什么,你确定你得到了你想要的吗?把它记录在哪里。
id = '12';
$.get('/page.php?id='+id, function(data) {

        // split input name by hyphen
        m = $(data).find('input').attr('name').split('-');

        // build new input name attribute 
        inputname = m[0] + '-' + id + '-' + m[2] + '-' + m[3] + '-' + m[4] + '-' + m[5];

        // apply new input name to data ??? this part I'm stuck on.
        $(data).find('input').attr('name', inputname);

});
id = '12';
$.get('/page.php?id=' + id, function (data) {
    var $data = $(data);

    // split input name by hyphen
    $data.find('input').attr('name', function (idx, name) {
        var m = name.split('-');
        var inputname = m[0] + '-' + id + '-' + m[2] + '-' + m[3] + '-' + m[4] + '-' + m[5];
        return inputname;
    });

    //be careful that the contents of `data` still will not have the updated name, but the contents of the jQuery wrapper $data will have the updated name
});