相关疑难解决方法(0)

如何检查页面上是否已存在具有ID的对象?

可能重复:
jQuery是否存在"exists"函数

比如说你有div:

<div id="hello"></div>
Run Code Online (Sandbox Code Playgroud)

而且你正在动态创建一个div:

<div id="hello"></div>
Run Code Online (Sandbox Code Playgroud)

是否有一个可以在Jquery中使用的函数,它将检查是否已在页面上存在具有您要创建的ID的对象?

javascript jquery jquery-selectors

20
推荐指数
2
解决办法
8539
查看次数

使用Javascript在单独的表单页面上使用图像文件名更新隐藏的表单字段

我有一个定制的Django wizard_form.html,它在我的调查的三个不同页面上显示用户3个不同的图像.

我正在尝试使用以下脚本更新3个不同页面上的3个隐藏表单字段,其内容value="{{display_image}}"为存储在数据库中显示给用户的图像文件名的方式

这适用于第一页/图像,例如

<input id="id_9-slider_one_image" name="9-slider_one_image" type="hidden" value="P1D1.jpg"/>
Run Code Online (Sandbox Code Playgroud)

但我似乎无法让它在第二或第三

<input id="id_10-slider_two_image" name="10-slider_two_image" type="hidden" />
Run Code Online (Sandbox Code Playgroud)

谁能告诉我我做错了什么?

我的守则

{% if wizard.steps.current in steps %}      

<div class="image_rating">      
    <img src="{% static "survey/images/pathone/" %}{{display_image}}" 
         value="{{display_image}}" onload="updateInput1(this); updateInput2(this); updateInput3(this);"/>                                                                                   
</div>  



<script type="text/javascript">
function updateInput1(ish) {
    var valueAttribute = ish.getAttribute("value");
    document.getElementById("id_9-slider_one_image").setAttribute(
    "value", valueAttribute);
}

function updateInput2(ish) {
    var valueAttribute = ish.getAttribute("value");
    document.getElementById("id_10-slider_two_image").setAttribute(
    "value", valueAttribute);
}

function updateInput3(ish) {
    var valueAttribute = ish.getAttribute("value");
    document.getElementById("id_11-slider_three_image").setAttribute(
    "value", valueAttribute);
}

</script>
Run Code Online (Sandbox Code Playgroud)

任何帮助都是一如既往,非常感谢,谢谢.

html javascript django

7
推荐指数
1
解决办法
858
查看次数

标签 统计

javascript ×2

django ×1

html ×1

jquery ×1

jquery-selectors ×1