Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我在Javascript中有一个错误,带有A href_Javascript_Jquery_Html_Xhtml - Fatal编程技术网

我在Javascript中有一个错误,带有A href

我在Javascript中有一个错误,带有A href,javascript,jquery,html,xhtml,Javascript,Jquery,Html,Xhtml,我不明白为什么这是个问题。 有人能解释一下这个问题吗?也许是一个可能的解决办法。 多谢各位 错误: 在此上下文中,不允许XHTML元素“a”作为XHTML元素“script”的子元素 代码: //安迪·兰顿的表演/隐藏/迷你手风琴-2009年11月23日更新 //最新版本@http://andylangton.co.uk/jquery-show-hide //这告诉jquery在DOM就绪后运行下面的函数 $(文档).ready(函数(){ //为显示/隐藏链接选择文本-可以包含HTML(例如

我不明白为什么这是个问题。 有人能解释一下这个问题吗?也许是一个可能的解决办法。 多谢各位

错误: 在此上下文中,不允许XHTML元素“a”作为XHTML元素“script”的子元素

代码:


//安迪·兰顿的表演/隐藏/迷你手风琴-2009年11月23日更新
//最新版本@http://andylangton.co.uk/jquery-show-hide
//这告诉jquery在DOM就绪后运行下面的函数
$(文档).ready(函数(){
//为显示/隐藏链接选择文本-可以包含HTML(例如图像)
var showText='More Info';
var hideText='Less Info';
//初始化可见性检查
var为可见=假;
//使用“toggle”类将显示/隐藏链接附加到元素前面的元素
***$('.toggle').prev().append('()')***
//使用“toggle”类隐藏所有元素
$('.toggle').hide();
//捕获切换链接上的单击
$('a.toggleLink')。单击(函数(){
//切换可见性
is_visible=!is_visible;
//根据图元是显示还是隐藏,更改链接
$(this).html((!是否可见)?showText:hideText);
//切换显示-取消注释下一行的基本“手风琴”样式
//$('.toggle').hide();$('a.toggleLink').html(showText);
$(this.parent().next('.toggle').toggle('slow');
//返回false,因此不遵循任何链接目标
返回false;
});
});

HTML和XHTML之间存在差异。在XHTML中,脚本没有CDATA内容类型:内容的处理方式与任何其他元素完全相同。这不仅仅是一个NetBeans问题

因此,有几种解决方案:

  • 将脚本放在一个单独的文件中,这样它的内容就不会被XML解析器破坏。这是最好的解决方案,因为它没有任何缺点。它适用于HTML和XHTML

  • 确保内容不包含任何
    ,您不能将锚定标记放在脚本标记内。有点不言自明。将您的XHTML转换为HTML5?能否围绕class=“toggle”发布html?尝试拆分标记:
    $('.toggle').prev().append('('+showText+'))此错误来自何处?是来自某个验证器吗?我觉得你的验证器不够聪明。您想要的任何HTML都可以放在javascript字符串中。这个错误在我看来是假的。
    
        <script type="text/javascript"> 
             // Andy Langton's show/hide/mini-accordion - updated 23/11/2009
             // Latest version @ http://andylangton.co.uk/jquery-show-hide
    
             // this tells jquery to run the function below once the DOM is ready
             $(document).ready(function() {
    
                  // choose text for the show/hide link - can contain HTML (e.g. an image)
                  var showText='More Info'; 
                  var hideText='Less Info';
    
                  // initialise the visibility check
                  var is_visible = false;
    
                  // append show/hide links to the element directly preceding the element with a class of "toggle"
                 ***$('.toggle').prev().append(' (<a href="#" class="toggleLink">'+showText+'</a>)');***
    
                 // hide all of the elements with a class of 'toggle'
                 $('.toggle').hide();
    
                 // capture clicks on the toggle links
                 $('a.toggleLink').click(function() {
    
                        // switch visibility
                        is_visible = !is_visible;
    
                       // change the link depending on whether the element is shown or hidden
                       $(this).html( (!is_visible) ? showText : hideText);
    
                       // toggle the display - uncomment the next line for a basic "accordion" style
                       //$('.toggle').hide();$('a.toggleLink').html(showText);
                       $(this).parent().next('.toggle').toggle('slow');
    
                       // return false so any link destination is not followed
                       return false;
    
                   });
             });
        <script>