要更改指定的标签,请随意打开文件,我正在尝试再次保存文件。
抱歉,我使用了翻译 如何用jquery标签代替......?
test.html↓
<banner_0101>
<div class="banner"><a href="#" rel="external"><img src="test.jpg" ></a></div>
</banner_0101>
<banner_0127>
<div class="banner"><img src="http://test.jpg" ></div>
</banner_0127>
test.php↓
<div id="form">
<form action="testok.php" method="POST">
<div>
<label for="cate">CATE_NUMBER</label>
<input type="text" name="cate" id="cate">
</div>
<div>
<label for="href">A href </label>
<input type="text" name="href" id="href">
</div>
<div>
<label for="imgsrc">Img src</label>
<input type="text" name="imgsrc" id="imgsrc">
</div>
<div>
<input type="submit" value="OK">
</div>
</form>
</div>
ex )
POST Value
test.ok ->
$_POST['cate'] -> banner_0101
$_POST['href'] -> /test1.php
$_POST['imgsrc'] -> testok.jpg
test.html ↓
<banner_0101>
<div class="banner"><a href="/test1.php" rel="external"><img src="testok.jpg" ></a></div>
</banner_0101>
**How do I resolve this problem?**
答案 0 :(得分:0)
许多解决方案之一(找到特定横幅并使用.find()
和.replaceWith())
替换DOM)可以是这样的,无需转到PHP,只需在jquery中添加此脚本:
$('#form form').on('submit', function(e){
e.preventDefault(); //Stops your form default behavior
banner = $('#cate').val(); //banner value
link = $('#href').val(); //link
imgsrc = $('#imgsrc').val(); //img src
newDom = $('<'+ banner +'>').html($('<div>' , {'class' : 'banner'}).append($('<a>' ,{'href' : link }).append($('<img>',{'src': imgsrc })))); //your new HTML
$('body').find(banner).replaceWith(newDom); //find the specific banner and replace existing banner with new DOM
});