获取img.src值(路径名) [英] Getting img.src value (path name)
本文介绍了获取img.src值(路径名)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个注册页面的表单。表单包含一个图像,该图像根据情况更改其src。
在提交表单时激活的脚本中,如果该图像具有特定的src,我希望表单调用警报,因此我需要一种检索和比较值的方法。
I have a form for a registration page. The form contains an image that changes its src dependant on a situation. Within a script which activates upon submission of the form, I want the form to call an alert if that image has a particular src, so I need a way of retrieving and comparing the value.
HTML:
<form action="register_submit.php" method="post" name="mainform" enctype="multipart/form-data" onSubmit="return checkForm(this);return false;">
JS:
function checkForm(f)
{if ([image src value] == "pictures/apic.png")
{
alert("error picture is apic");
return false;
}
else
{
f.submit();
return false;
}
}
以下是完整的相关代码:
Here is the relative code in full:
<script type="text/javascript">
function checkForm(f)
{if ([image src value] == "pictures/apic.png")
{
alert("error picture is apic");
return false;
}
else
{
f.submit();
return false;
}
}
</script>
<form action="register_submit.php" method="post" name="mainform" enctype="multipart/form-data" onSubmit="return checkForm(this);return false;">
<div class="required">
<label for="first_name">*First Name:</label>
<input type="text" name="first_name" id="first_name" class="inputText" onkeyup="checkFName(this.value);" onblur="checkFName(this.value);" maxlength="20" size="10" value="" />
<img id="FName_Status" name="FName_Status" src="/pictures/bad.png" style="margin-left:5px; position:absolute;" alt="FName_Status" />
</div>
(OTHER OBJECTS)
</form>
<input type="submit" name="sub" class="inputSubmit" value="Submit »"/>
推荐答案
使用此:
if (document.getElementById('FName_Status').getAttribute('src') == "pictures/apic.png")
这篇关于获取img.src值(路径名)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文