小编min*_*men的帖子

使用 JS 或 jQuery 将新节点添加到本地 XML 文件

我想从用户输入向 XML 文件添加新元素。我尝试了很多可能的方法,但没有一个对我有用:(

如何使用 JavaScript 或 jQuery 将新节点/元素/项目添加到现有本地 XML 文件?

这是我目前的状态:

function addElement() {
    var xml;
    if (window.activexobject) {
        xml = new activexobject("microsoft.xmlhttp");
    } else {
        xml = new xmlhttprequest();
    }
    xml.onreadystatechange = function () {
        if (xml.readystate == 4 && xml.status == 200) {
            var resp = xml.responsexml;
            var user = xml.responsexml.createelement("User");

            var name = xml.responsexml.createelement("name");
            name.appendchild(xml.responsexml.createtextnode("sof_user"));

            var admin = xml.responsexml.createelement("admin");
            admin.appendchild(xml.responsexml.createtextnode("false"));

            user.appendchild(name);
            user.appendchild(admin);
            xml.responsexml.documentelement.appendchild(user);
        }
    }
xml.open("get", "users.xml", true);
xml.send(null);
}
Run Code Online (Sandbox Code Playgroud)

XML 应如下所示:

<Users>
    <User>
        <name>testuser</name>
        <admin>true</admin>
    </User> …
Run Code Online (Sandbox Code Playgroud)

javascript xml jquery

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

无法通过<%= variable%>访问JS/jQuery中的变量

我正在尝试从JavaScript/jQuery访问asp.net变量(c#).

我在这里这里找到了解决方案.但不幸的是,这些对我不起作用.

这是一个片段:
Default.aspx.cs

public partial class Default : System.Web.UI.Page
{
    public string CurrentUser { get; set; }
    protected void Page_Load(object sender, EventArgs e)
    {
        CurrentUser = User.Identity.Name.Split('\\')[1]; //I need the value of "CurrentUser"
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)


的script.js

$(document).ready(function (){
    var _currentUser = "<% =CurrentUser %>"; // e.g. _currentUser = "minimen"
    ...
});
Run Code Online (Sandbox Code Playgroud)

_currentUser的值始终为"<%= CurrentUser%>".

有任何想法吗?

javascript c# asp.net jquery

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

如何将自定义EXIF标记添加到图像

我想为图像添加一个新标签("LV95_original")(JPG,PNG或其他东西..)

如何为图像添加自定义EXIF标签?

这是我到目前为止所尝试的:

using (var file = Image.FromFile(path))
{
    PropertyItem propItem = file.PropertyItems[0];
    propItem.Type = 2;
    propItem.Value = System.Text.Encoding.UTF8.GetBytes(item.ToString() + "\0");
    propItem.Len = propItem.Value.Length;
    file.SetPropertyItem(propItem);
}
Run Code Online (Sandbox Code Playgroud)

这就是我研究的内容:

添加自定义属性:这使用不同的东西

SetPropert:这会更新一个属性,我需要添加一个新属性

添加EXIF信息:这会更新标准标签

添加新标签:这是我尝试过的,没有用

c# exif metadata image

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

标签 统计

c# ×2

javascript ×2

jquery ×2

asp.net ×1

exif ×1

image ×1

metadata ×1

xml ×1