Attributes 从没有ID的子元素获取属性值-JQuery

Attributes 从没有ID的子元素获取属性值-JQuery,attributes,children,Attributes,Children,假设我有以下代码: <div id="Element_1" class="draggable"> <input type="text" placeholder="Enter Your Text Here" style="width:300px;"> </div> <div id="Element_2" class="draggable"> <textarea placeholder="Enter Your Text Here" style="

假设我有以下代码:

<div id="Element_1" class="draggable">
<input type="text" placeholder="Enter Your Text Here" style="width:300px;">
</div>
<div id="Element_2" class="draggable">
<textarea placeholder="Enter Your Text Here" style="width:400px;height:200px;"></textarea>
</div>
谢谢


卡尔

你的代码有点过分了

  • .live()在jQuery 1.7中被弃用,在1.9中被完全删除,jQuery文档说应该改用.on()
  • 一切都很简单。您可以尝试以下方法:
    • 方法通常返回元素的子元素集,但在您的示例中只有一个,所以它是可以的
    • .width()和.height()返回类似“300px”的值,因此我们使用parseInt()生成int值
    • .click(handler)是.on(“click”,handler)的快捷方式

    您的问题缺少关键信息。您使用什么编程语言/库/框架访问数据?是JavaScript、C++、.NET、XMLNUKE、XECECES……还添加一些代码,显示如何读取数据,以便我们知道从何处开始。顺便说一句:XML不是代码,它是数据。哦,对不起!!哈哈JQuery…谢谢你!太好了!如何获取“标记名”或“类型”?没关系,我找到了!谢谢
    $(".draggable").live("click",function(){
        var SelectedID = $(this).attr("id");
        $("*").removeClass("selected");   
        var Element = $("#"+SelectedID,":first-child").addClass("selected").html();
    
        PlaceholderPropValue = $(element).attr("placeholder");
        StylesPropValue = $(element).attr("style");
        WidthProp = StylesProp.match(/(width:)([0-9].*?)(?=px;)/)[2];
        HeightProp = StylesProp.match(/(height:)([0-9].*?)(?=px;)/)[2];
        alert(PlaceholderPropValue+ " " +WidthProp+ " " +HeightProp);
    });
    
    $('.draggable').click(function(){
        var $element = $(this).children();
        var width = parseInt($element.width());
        var height = parseInt($element.height());
        var placeholder = $element.attr('placeholder');  
        alert(placeholder+ " " +width+ " " +height);
    })