如何替换元素属性中的部分文本

时间:2015-03-12 07:47:29

标签: javascript html

您好我想将textbox1值放在'输入代码的位置'在下面的代码中。请帮帮我。

<script >
 function myfunction() { 
            var first = document.getElementById("textbox1").value;
            var textbox3 = document.getElementById('textbox3');
            textbox3.value=first;
          } 

    </script>

 <body> 


 <input type="text" name="textbox3" id="textbox3" readonly="true"/>
 <object type="application/x-shockwave-flash" data="Working.swf" width="600"  
         height="600">
   <param name= background-color="Black"/>
   <param name="movie" value="Working.swf" />
   <param name="flashvars" value="ImgUrl=`enter code here`" />
</object>

1 个答案:

答案 0 :(得分:0)

**应将问题更改为 - &#39;如何替换元素属性中的部分文字&#39;

使用javascript很容易。

你可以在这里玩http://jsfiddle.net/6np2g6kw/并学习一些东西。

或获取以下代码

        var first = document.getElementById("textbox1").value;
        var textbox3 = document.getElementById('textbox3');
        textbox3.value=first;

        //getting the flash object element
        var flash_object = document.getElementById("myObject");
        //getting the desired param by its name
        var flash_vars = flash_object.getElementsByTagName('param')[2];

        //getting the value attribute value
        var falsh_vars_value = flash_vars.attributes.value.textContent;
        //splitig by comma to seperate the "enter code here"
        falsh_vars_value = falsh_vars_value.split('`');
        // this option is more generic
        //building the new string the the 'textbox1' value between the commas
        var flash_vars_new_value = falsh_vars_value[0] +'`' + first + '`' + falsh_vars_value[2];
        // this is and options as well
        //falsh_vars_value = falsh_vars_value.replace('enter code here', first);
        //you can alow do with regex its abit more complex.
        // read here - http://regexone.com/
        //setting the new value to the element
        flash_vars.attributes.value.textContent= flash_vars_new_value;