ul"); ul.append('+'+$('#authorFiel-6ren">
gpt4 book ai didi

javascript - 在grails gsp标签中输入jquery语句

转载 作者:行者123 更新时间:2023-12-02 23:59:21 25 4
gpt4 key购买 nike

当我尝试在 grails 中使用 jQuery 句子时,出现多重编译错误 <g:link>标签

var ul = $("#authorList > ul");
ul.append('<li><g:link action="show" controller="author" id="'+$('#authorID').val()+'">+'+$('#authorField').val()+'</g:link></li>')

我只在 id=""属性内的 jquery 中遇到错误,这样

ul.append('<li><g:link action="show" controller="author" id="">+'+$('#authorField').val()+'</g:link></li>')

该页面正在运行,但我无法获取动态链接,它的语法如何正确?

<小时/>

URI: /ComplexTables/book/create Class
org.codehaus.groovy.control.MultipleCompilationErrorsException
Message: startup failed: 19: illegal string body character after dollar sign; solution: either escape a literal dollar sign "\$5" or bracket the value expression "${5}" @ line 19, column 210. l()\'"', 35, it) { return "'+$('#authorI ^ 1 error

<小时/>

grails-app\views\book_form.gsp 第 35 行左右

function appendAuthor(ev) {
34: var ul = $("#authorList > ul");
35: ul.append('<li><g:link action="show" controller="author" id="'+$('#authorID').val()'">+'+$('#authorField').val()+'</g:link></li>')
36: }
37:</script>

最佳答案

我不知道GSP,但一般ID不能以数字开头。

"Using characters except ASCII letters, digits, '_', '-' and '.' may cause compatibility problems, as they weren't allowed in HTML 4. Though this restriction has been lifted in HTML 5, an ID should start with a letter for compatibility."

如果你只使用 DOM getElementById () 方法而不是 jQuery 不是更好

ul.append('<li><g:link action="show" controller="author" id="sth_'+document.getElementById('authorID').value+'">+'+document.getElementById('authorID').value+'</g:link></li>')

关于javascript - 在grails gsp标签中输入jquery语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55244548/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com