简体   繁体   English

按下按钮更改对象标签的数据值

[英]Change data value of object tag on button press

I have an object tag with a blank data value and a menu of hyperlinks. 我有一个带有空白数据值的对象标签和一个超链接菜单。 I need the data value of the object tag to change to the href link set in each menu item upon click, preferably using javascript. 单击后,我需要对象标记的数据值更改为在每个菜单项中设置的href链接,最好使用javascript。

All help appreciated and thank you in advance. 感谢所有帮助,并提前感谢您。

EDIT : 编辑
Lets say i have an object tag with data="" If Link A has a href="this.html" I want the data attribute of object to become data="this.html" when Link A is clicked 可以说我有一个带有data =“”的对象标记,如果链接A具有a href="this.html" data="this.html"当单击链接A时,我希望对象的数据属性变为data="this.html"

By going through your question what i analyzed is you have anchor tags on clicking those anchor tag " the value attached to that tag should pass to the objects" 通过回答您的问题,我分析了您是否在单击那些锚定标记时拥有了锚定标记“附加到该标记的值应该传递给对象”

<html>
<head>
<script type="text/javascript" src="jquery.js"></script>    
<script type="text/javascript">
$(document).ready(function(){

$("a").click(function() {

var obj=new Object;
obj={};

var thisObjectText=$(this).attr("name");

obj.value=thisObjectText;

alert("object value on clicking links " + obj.value);

});

});



</script>
</head>
<body>

<div id="test">
<a href="#" name="test-1">Aaaa</a>
<a href="#" name="test-2">Baaa</a>
<a href="#" name="test-3">Caaa</a>
<a href="#" name="test-4">Daaa</a>
</div>
<div id="result">

</div>

</body>
</html>   

On clicking the Anchors link the object data gets changed ,hoping this is what you want 单击“锚点”链接后,对象数据将更改,希望这就是您想要的

  <html>
        <head>
        <script type="text/javascript" src="jquery.js"></script>    
        <script type="text/javascript">
        $(document).ready(function(){

        $("a").click(function() {

        var thisObjectText=$(this).attr("href");
        if(thisObjectText!=null && thisObjectText!="")
        {
        $('#swf').attr("data",thisObjectText);
        alert($('#swf').attr("data"));
        }


        });

        });



        </script>
        </head>
        <body>

        <div id="test">
        <a href="#first" name="test-1">Aaaa</a>
        <a href="#second" name="test-2">Baaa</a>
        <a href="#third" name="test-3">Caaa</a>
        <a href="#fourth" name="test-4">Daaa</a>
        </div>


        <object id="swf" width="400" height="400" data=""></object> 
        </body>
    </html> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM