这是我的嵌入:
<embed style="border:5px solid black" width="100" height="180" align="middle" flashvars="datapath=http://www.foobar.org/gadgets&curr=$&menucolor=0xef2e24&menutitle=foobar&supid=0&eid=1107183&tid=6420765" allowscriptaccess="sameDomain" wmode="transparent" quality="high" src="https://www.foobar.org/atf/cf/%7B26ab1627-1b72-418e-a4bd-96e83ca127ed%7D/foobar.SWF" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="flashthermometer">
我想使用jQuery将eid=1107183
替换为eid=1134229
。
我已经研究过以下几点:
var textToReplace = "datapath=http://www.foobar.org/gadgets&curr=$&menucolor=0xef2e24&menutitle=foobar&supid=0&eid=1107183&tid=6420765"
jQuery('#flashthermometer').find('embed').attr('flashvars', textToReplace);
但这似乎不起作用。
感谢任何帮助。
感谢。
答案 0 :(得分:0)
试试这个:
$(document).ready(function () {
var new_eid = 1134229;
var $em = $('embed');
var data = $em.attr('flashvars'); // gets the string
var arr = data.split('&'); // turns string into array
var eid = arr[5].split('='); // gets the eid string and turns it key/value
eid[1] = new_eid; // sets the new value
eid = eid.join("="); // rebuilds the new eid string
arr[5] = eid; // sets the new eid into query array
data = arr.join("&"); // turns query back to string
$em.attr('flashvars', data); // sets the embed with new string
});
或regex
:
var new_eid = 1134229;
var $em = $('embed');
var data = $em.attr('flashvars');
var edited = data.replace(/(eid=)[^\&]+/, '$1' + new_eid);
$em.attr('flashvars', edited );
答案 1 :(得分:-1)
我创建了一个 Demo ,其输入(仅接受数字)会更改您的嵌入属性值:
$('embed').attr('flashvars',
$('embed').attr('flashvars').replace(/(?:(eid\=))([0-9]+)/, "$1"+newValue)
);
希望有所帮助