Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.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
jQuery-在最近/最近的DIV中选择输入&为每个输入添加值_Jquery_Html_Forms_Parent Child_Closest - Fatal编程技术网

jQuery-在最近/最近的DIV中选择输入&为每个输入添加值

jQuery-在最近/最近的DIV中选择输入&为每个输入添加值,jquery,html,forms,parent-child,closest,Jquery,Html,Forms,Parent Child,Closest,在我的应用程序中,我使用$.get和yahoo API从用户给定的URL获取open-gragh/og:title和description 它可以作为代码片段吹,或者您可以访问 $'get-social-data-from-url'.keyup函数{ var query='从html中选择*,其中url='+$'输入'.val+'和xpath=*'; var url='1〕https://query.yahooapis.com/v1/public/yql?q='+encodeURICompon

在我的应用程序中,我使用$.get和yahoo API从用户给定的URL获取open-gragh/og:title和description

它可以作为代码片段吹,或者您可以访问

$'get-social-data-from-url'.keyup函数{ var query='从html中选择*,其中url='+$'输入'.val+'和xpath=*'; var url='1〕https://query.yahooapis.com/v1/public/yql?q='+encodeURIComponentquery; $.geturl,functiondata{ var html=$data.find'html'; $'title'.valhtml.findmeta[property='og:title'].attr'content'| |'no title found'; $'description'.valhtml.findmeta[property='og:description'].attr'content'| |'no description found'; }; }; 输入{ 宽度:90%; 高度:50px; 边缘底部:20px; } 标题 描述
这就是解决问题的方法。首先将数据添加到具有相同值但不同数据名称的每个输入中

例如:


动态创建的元素通常可以具有相同的类,但不能具有相同的ID。如果你因为使用某个插件而无法控制,那么该插件的设计/编写就严重错误。为了方便地管理动态创建的元素,您可以始终使用索引作为基本id的前缀/后缀来创建不同的id。@KingKing感谢您的回复。是的,没错,我有不同的ID,但我不知道IDplugin适用于每个输入。但我仍然可以给他们一个固定的身份证。总之,我在每个输入上都有固定的和不同的ID。感谢您的帮助。
<input class="post-title-create" data-title-id="attributes_1" type="text"  id="attributes_1493294690538_title">
$(function () {
    var fileFieldId;
    var fileFieldVal;
    var fileFieldClass;
    var query;
    var apiUrl;
    $(".get-social-data-from-url").keyup(function () {
        fileFieldId = $(this).attr('id');
        fileFieldClass = $(this).attr('class');
        fileFieldVal = $(this).val();
        query = 'select * from html where url="' + $(this).val() + '" and xpath="*"';
        apiUrl = 'https://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent(query);

        $("h4[data-preview-id='" + fileFieldId + "']" ).text('updated');
        $("input.post-link-create[data-link-id='" + fileFieldId + "']" ).val(fileFieldVal);

        $.get(apiUrl, function(data) {
          var html = $(data).find('html');
          $("input.post-title-create[data-title-id='" + fileFieldId + "']" ).val(html.find("meta[property='og:title']").attr('content') || 'no title found');
          $("textarea.post-description-create[data-description-id='" + fileFieldId + "']" ).val(html.find("meta[property='og:description']").attr('content') || 'no title found');
          $("input.post-remote-image-create[data-remoteimg-id='" + fileFieldId + "']" ).val(html.find("meta[property='og:image']").attr('content') || 'no title found');
        });

    });
});