Javascript中的对象预期错误 [英] Object expected error in Javascript

查看:72
本文介绍了Javascript中的对象预期错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我收到以下代码的对象预期错误:在第14行Char 1中,请建议。



 <   script     type   =  text / javascript >  
function (){
alert( 在第一个函数);
}
function 秒(){
alert( < span class =code-string> in second function);
}

< / script >

< < span class =code-leadattribute> table id = 1234 >
< tr > < td > < ; a onclick = First() > 首先< / a > < / td > ; < / tr >
< tr > < td > < a onclick = 秒() > 第二个< / a > < / td > < / tr >
< / table >
< id = abcd >
< ; tr >
< td > 序列号1:< < span class =code-leadattribute> / td >
< td > abcd < < span class =code-leadattribute> / td >
< / tr >
< / table >





提前致谢。



问候,

Raghu

解决方案





我不确定你的onclick属性中的character字符是什么,但我认为这些需要改为常规o



类似......

来自:
<前lang =HTML> < 表格 > < < span class =code-leadattribute> tbody > < tr > < td > < a önclick = First() > 首先< / a > < < span class =code-leadattribute> / td > < / tr > < / tbody > < / table >
< 表格 > < tbody > < tr > < td > < a önclick = Second() > 第二个< / a > < / td > < < span class =code-leadattribute> / tr > < / tbody > < / table >





要:

 <   table  < span class =code-keyword>>  <   tbody  >  <跨度class =code-keyword><   tr  >  <   td  >  <   div     onclick   =  First(); > 首先<   / div  >  <   / td  >  <   / tr  >  <   / tbody  >  <   / table  >  
< table > < tbody > < tr > < td > < div onclick = 秒(); > < / div > < / td > < / tr > < / tbody > < / table >





我还为divs换了你的archor标签,因为使用没有href值的锚标签是不好的做法。

我还在onclick方法函数调用后添加了缺少的分号。



希望它有所帮助。


困惑,我尝试了你的代码。它按预期工作。也许问题出在你的观察中;或者您使用的代码与您在问题中发布的代码不同。



-SA


在上面粘贴的代码中,您已将您的函数命名为showmyTable(),但是当您在html部分中使用它时,它是ShowmyTable()。

尝试以下代码

< script type =   text / javascript> 
function ShowmyTable() // 更改从showmyTable()到ShowmyTable()的函数名称
{
document .getElementById( tabinfHide)。style.display = ;
document .getElementById( PackageExpandAnchor).style.display = none;
document .getElementById( PackageHideAnchor).style.display = block;
}
function HideTable(){
document .getElementById( tabinfHide)。style.display = none;
document .getElementById( PackageHideAnchor).style.display = none;
document .getElementById( PackageExpandAnchor).style.display = block;
}
< / script>



 <      id   =  tabinf >  
< span class =code-keyword>< tr >
< td class = tdSpecialtitle colspan = 2 > 包装文件夹:< / td >
< / tr >
< tr >
< td class = tdinfError colspan = 2 > 注:以下文件夹中包含文件夹:%ProgramData%\ AppV \ 3E2E9B5B-8E7B-4665-A544-D47C8CB76EA8 \ E8806E62-BFF8-4AA9-B656-B4DFAB6233B2 < / td >
< / tr >
< tr >
< td class = tdinfError < span class =code-attribute> colspan = 2 > 注意:VFS和Scripts文件夹下的文件夹以粗体列出紫色其他文件夹以蓝色< / td >
< / tr >
< tr < span class =code-keyword>>
< td class = tdinfStitle colspan = 2 > < div id = PackageExpandAnchor önclick = ShowmyTable(); style = display:none > +展开文件夹< / div > < < span class =code-leadattribute> / td >
< / tr >
< tr >
< td class = tdinfStitle colspan = 2 > < div id = PackageHideAnchor önclick = HideTable(); > - 折叠文件夹< / div > < / td >
< / tr >
< / table >
< table id = tabinfHide >
< tr >
< td class = tdinfLWarning > 文件夹1:< / td >
< td class = tdinfWarning > Root \ VFS \Profile\geoSCOUT \Templates \ frameWORKs < / td >
< / tr >
< / table >





希望有所帮助


Hi,

I am getting "Object expected" error for the below piece of code: in the line 14 Char 1, Please suggest.

<script type="text/javascript">
function First(){
alert("in First function");
}
function Second(){
alert("in Second function");
}

</script>
 
<table id="1234">
<tr><td><a  onclick="First()">First</a></td></tr>
<tr><td><a  onclick="Second()">Second</a></td></tr>
</table>
<table id="abcd">
<tr>
<td>Serial Number 1 :</td>
<td>abcd</td>
</tr>
</table>



Thanks in advance.

Regards,
Raghu

解决方案

Hi,

I'm not sure what the ö character in your onclick attributes are, but I think these need to be changed to regular o

Something like ...
From:

<table><tbody><tr><td><a önclick="First()">First</a></td></tr></tbody></table>
<table><tbody><tr><td><a önclick="Second()">Second</a></td></tr></tbody></table>



To:

<table><tbody><tr><td><div onclick="First();">First</div></td></tr></tbody></table>
<table><tbody><tr><td><div onclick="Second();">Second</div></td></tr></tbody></table>



I've also swapped out your archor tags for divs, as it's not good practise to use an anchor tag without an href value.
I also added the missing semi-colons after the function call in the onclick methods.

Hope it helps.


Puzzled, I tried your code. It works as expected. Perhaps the problem is in your observations; or you used the code different from the code you published in your question.

—SA


In your code pasted above, you have named your function "showmyTable()" but when you are using it in the html part it is "ShowmyTable()".
Try the below code

<script type="text/javascript">
function ShowmyTable() //Change the name of the function from showmyTable() to ShowmyTable()
{
	document.getElementById("tabinfHide").style.display = "block";
	document.getElementById("PackageExpandAnchor").style.display = "none";
	document.getElementById("PackageHideAnchor").style.display = "block";
}
function HideTable(){
	document.getElementById("tabinfHide").style.display = "none";
	document.getElementById("PackageHideAnchor").style.display = "none";
	document.getElementById("PackageExpandAnchor").style.display = "block";
}
</script>


<table id="tabinf">
<tr>
	<td class="tdSpecialtitle" colspan="2">PACKAGE FOLDERS :</td>
</tr>
<tr>
	<td class="tdinfError" colspan="2">NOTE : The Below folders are present in the folder: %ProgramData%\AppV\3E2E9B5B-8E7B-4665-A544-D47C8CB76EA8\E8806E62-BFF8-4AA9-B656-B4DFAB6233B2</td>
</tr>
<tr>
	<td class="tdinfError" colspan="2">NOTE : Folders under VFS and Scripts folder are listed in bold Purple Other folders are displayed in blue</td>
</tr>
<tr>
	<td class="tdinfStitle" colspan="2"><div id="PackageExpandAnchor" önclick="ShowmyTable();" style="display:none">+ Expand Folders</div></td>
</tr>
<tr>
	<td class="tdinfStitle" colspan="2"><div id="PackageHideAnchor" önclick="HideTable();">- Collapse Folders</div></td>
</tr>
</table>
<table id="tabinfHide">
<tr>
	<td class="tdinfLWarning">Folder 1 :</td>
	<td class="tdinfWarning"> Root\VFS\Profile\geoSCOUT\Templates\frameWORKs</td>
</tr>
</table>



Hope it helps


这篇关于Javascript中的对象预期错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆