我想把文本放在p标签里面
<p id="paragraph">Some text</p>
Run Code Online (Sandbox Code Playgroud)
我想将文本存储在这样的JavaScript变量中
var text = "Some text";
Run Code Online (Sandbox Code Playgroud)
我读到我必须添加
var text = document.getElementById("paragraph").innerHtml;
Run Code Online (Sandbox Code Playgroud)
但是变量的值是NULL或Undefined,我也喜欢这样
var text = document.getElementById("paragraph")[0].innerHtml;
Run Code Online (Sandbox Code Playgroud)
我有同样的问题!
我正在处理文件上传器,当输入被更改时上传图像我的代码是html中的表单
<form method="post" enctype="multipart/form-data">
<input name="uploaded[]" type="file" id="file_upload"/>
</form>
Run Code Online (Sandbox Code Playgroud)
我的JavaScript和Ajax:
document.getElementById("file_upload").onchange = function() {
var id = document.getElementById("user_id").innerHTML;
var file = document.getElementById("file_upload").files[0];
alert(file.size);
var formdata = new FormData();
formdata.append("filer",file,true);
var ajax = new XMLHttpRequest();
ajax.onreadystatechange =
function(){
if(ajax.readyState==4 && ajax.status==200){
document.getElementById("one").remove();
var img = document.createElement('img');
var first_path = '/user_image/';
var path = first_path.concat(id,'.png');
img.setAttribute('alt','User image');
img.setAttribute('id','one');
img.setAttribute('src',path);
document.getElementById("user").appendChild(img);
alert("end");
}
else{
document.getElementById("one").remove();
var img = document.createElement('img');
img.setAttribute('src','/img/loading.gif');
img.setAttribute('alt','User image');
img.setAttribute('id','one');
document.getElementById("user").appendChild(img);
}
}
ajax.open("POST","upload_image.php");
ajax.setRequestHeader("Content-Type", "multipart/form-data");
ajax.send(formdata);
};
Run Code Online (Sandbox Code Playgroud)
而我的PHP代码很简单就是测试一切是否正常
require("../includes/config.php"); …Run Code Online (Sandbox Code Playgroud) 我用html制作了选择标签,其中包含国家的所有名称,我想用搜索栏搜索他们的值而没有任何插件或插件可能吗?
如何获取具有相同类的元素值的数组?
当我这样做时,我只得到第一个元素,但我想要一个完整的数组:
var classes = document.querySelector(".klass").value;
alert(classes); //Outputs only the first element
Run Code Online (Sandbox Code Playgroud)
我想获得输入值的完整数组:
<input type="text" class="klass" />
<input type="text" class="klass" />
<input type="text" class="klass" />
Run Code Online (Sandbox Code Playgroud)
那可能吗?