如何复制隐藏的输入值属性,对其进行操作然后使用单击功能进行更改?更确切地说:
此:
<input type="hidden" id="destination" value="/change1/change2/fixed-part" />
对此:
<input type="hidden" id="destination" value="/changedtext/fixed-part" />
我做了一些过程,但无法获得理想的结果。到目前为止,我得到了价值,操纵它(不确定它是否正常工作)但不能用原来的替代它。
这是jsfiddle: https://jsfiddle.net/3ry4cc79/1/
答案 0 :(得分:0)
试试这个,
document.getElementById('destination').value = "/changedtext/fixed-part";
答案 1 :(得分:0)
$("button").click(function(event){
event.preventDefault();
$('#destination').val(function() {
return this.value.replace('change1', 'changedtext')
});
alert("Changed Value:"+$('#destination').val());
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="hidden" id="destination" name="_wp_http_referer" value="/change1/change2/fixed-part" />
Try this should work,
<input type="hidden" id="destination2" name="_wp_http_referer" value="/changedtext/fixed-part" />
<button>Click to change the value</button>
&#13;
答案 2 :(得分:0)
// Get the hidden element
let el = document.getElementById('destination');
// Add the new val you want to minipulate the hidden elemets value with
let newVal = 'changedtext';
// then at a later state, you click the button
this.clickToChange = function () {
// and voila, the value is replaced on the hidden element
el.value = el.value.replace('change1/change2', newVal);
}