2017-04-20 20 views
1

隠し入力値属性をコピーして操作し、クリック機能でどのように変更できますか?より正確には:元の値に基づいて入力値を変更

この:これに

​​

<input type="hidden" id="destination" value="/changedtext/fixed-part" /> 

私はいくつかのプロセスを作ったが、所望の結果を得ることができませんでした。これまでのところ、私は価値を得て、それを操作します(それが問題ないかどうかは分かりませんが、元のものと置き換えることはできませんでした)。ここで

はjsfiddleです:。 https://jsfiddle.net/3ry4cc79/1/

+1

、これを試してみてくださいヴァル(関数() {return this.value.replace( 'change1/change2'、 'changedtext' )}) ' – haim770

答えて

0

は `$( '#先')

document.getElementById('destination').value = "/changedtext/fixed-part"; 
+0

これは非常に簡単で素晴らしいです!どうもありがとうございました! –

+0

@RıfatYerusalmiあなたはようこそ... –

0

$("button").click(function(event){ 
 
    event.preventDefault(); 
 
    $('#destination').val(function() { 
 
      return this.value.replace('change1', 'changedtext') 
 
    }); 
 
    alert("Changed Value:"+$('#destination').val()); 
 

 
});
<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>

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); 
} 
関連する問題