小编Sje*_*kie的帖子

使用javascript从div获取价值:始终未定义

当我从div获取值时,我遇到了这个问题:

function sync(){
    var n1 = document.getElementById('editor').value;
    alert(n1);
    var n2 = document.getElementById('news');
    n2.value = n1;
}
Run Code Online (Sandbox Code Playgroud)

带id的div editor看起来像这样:

<div class='message'  id='editor' contenteditable="true" onkeyUp='sync()' style="color: black"></div>
Run Code Online (Sandbox Code Playgroud)

当我在那个div中添加一些内容时,它会提醒我未定义,并且也会在textarea中进行粘贴.所以问题显然是由此:

var n1 = document.getElementById('editor').value;
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

html javascript undefined

5
推荐指数
1
解决办法
2万
查看次数

Kotlin 注释不在 fieldDecleration 或已编译的 java 中

对于 Kotlin 中的数据对象,我为 GSON 添加了自定义注释以具有排除规则。

在过去,这工作得很好,现在它不会出现在我的类反射(this.javaClass.declaredFields[3].annotationsis null)中,也不会出现在编译的 java 输出中。

我尝试过不同的事情,比如升级我的 kotlin 版本、添加 kotlin-kapt、使用不同的@Retention类型、重新启动我的计算机(你永远不知道)并查看其他注释。这些其他注释(例如 Hibernate a @OneToOne)显示没有问题。

注解定义:

@Retention(AnnotationRetention.RUNTIME)
@Repeatable
@Target(
        AnnotationTarget.FIELD,
        AnnotationTarget.PROPERTY_GETTER,
        AnnotationTarget.PROPERTY_SETTER,
        AnnotationTarget.PROPERTY,
        AnnotationTarget.VALUE_PARAMETER
)
annotation class ExcludeFromJSON
Run Code Online (Sandbox Code Playgroud)

数据类中的用法:

@Entity
@Table(name = "user")
class User (

        var username: String = "",
        var email: String = "",

        @ExcludeFromJSON
        private var password: String
) {}
Run Code Online (Sandbox Code Playgroud)

我希望注释出现在 javaClass 反射和编译的 java 代码中。它两者都没有。

编译后的密码var(无注释...):

@Retention(AnnotationRetention.RUNTIME)
@Repeatable
@Target(
        AnnotationTarget.FIELD,
        AnnotationTarget.PROPERTY_GETTER,
        AnnotationTarget.PROPERTY_SETTER,
        AnnotationTarget.PROPERTY,
        AnnotationTarget.VALUE_PARAMETER
)
annotation class ExcludeFromJSON
Run Code Online (Sandbox Code Playgroud)

java annotations hibernate kotlin

5
推荐指数
1
解决办法
1758
查看次数

Javascript:显示所选图像

我试图这样做,当你选择你的图像时,它会直接显示它.当然你onchange在html 的东西中这样做.这就是我现在所拥有的:

function showImage(src, target) {
    var fr = new FileReader();

    fr.onload = function (e) { target.src = this.result; };

    src.addEventListener("change", function () {

        fr.readAsDataURL(src.files[0]);
    });

}
function putImage() {
    var src = document.getElementById("select_image");
    var target = document.getElementById("target");
    showImage(src, target);
}
Run Code Online (Sandbox Code Playgroud)
<img id="target" />
<input type="file" id="select_image" name="image" onchange="putImage()"> </input>
Run Code Online (Sandbox Code Playgroud)

这对我来说不是很奇怪.因为onchange有效.我可以通过警告事件来测试它.这很好用.javascript也适用于jsfiddle ..但这些东西并没有合并.我希望有人能帮帮忙

html javascript jquery

2
推荐指数
1
解决办法
6376
查看次数

标签 统计

html ×2

javascript ×2

annotations ×1

hibernate ×1

java ×1

jquery ×1

kotlin ×1

undefined ×1