使用 Javascript 在没有字段的 CRM 2016 表单中创建按钮
Create Button in CRM 2016 Form without a Field using Javascript
我必须在查找字段中创建一个按钮 我已关注此页面
http://bharathknight.blogspot.com/2015/03/create-button-inside-form-using.html 我添加了一个事件 onchange the lookup value 但第一个警报被触发但是第二个 none 并且没有显示任何按钮请帮助我我被困在这里
function createButton() {
alert("createButton");
var atrname = "xxxx";
if (document.getElementById(atrname ) != null) {
var fieldId = "field" + atrname ;
var elementId = document.getElementById(atrname + "_d");
var div = document.createElement("div");
div.style.width = "20%";
div.style.textAlign = "right";
div.style.display = "inline";
childDiv = elementId.getElementsByTagName('div')[0]
childDiv.style.display = "none";
elementId.appendChild(div, elementId );
div.innerHTML = '<button id="' + fieldId + '" type="button" style="margin-left: 4px; width: 50%;" >CRM Save Button</button>';
document.getElementById(atrname).style.width = "80%";
document.getElementById(fieldId ).onclick = function () { OnClickFunction(); };
}
}
function OnClickFunction() {
alert("clicked!");
}
随着涡轮形式的引入,情况发生了一些变化。如果要访问 DOM,请使用文档的父元素。
function createButton() {
var atrname = 'foobar';
if (window.parent.document.getElementById(atrname) != null) {
var fieldId = 'field' + atrname;
var elementId = window.parent.document.getElementById(atrname + '_d');
var div = window.parent.document.createElement('div');
div.style.width = '20%';
div.style.textAlign = 'right';
div.style.display = 'inline';
var childDiv = elementId.getElementsByTagName('div')[0];
childDiv.style.display = 'none';
elementId.appendChild(div, elementId);
div.innerHTML = '<button id="' + fieldId + '" type="button" style="margin-left: 4px; width: 50%;" >CRM Save Button</button>';
window.parent.document.getElementById(atrname).style.width = '80%';
window.parent.document.getElementById(fieldId).onclick = function () { OnClickFunction(); };
}
}
我必须在查找字段中创建一个按钮 我已关注此页面 http://bharathknight.blogspot.com/2015/03/create-button-inside-form-using.html 我添加了一个事件 onchange the lookup value 但第一个警报被触发但是第二个 none 并且没有显示任何按钮请帮助我我被困在这里
function createButton() {
alert("createButton");
var atrname = "xxxx";
if (document.getElementById(atrname ) != null) {
var fieldId = "field" + atrname ;
var elementId = document.getElementById(atrname + "_d");
var div = document.createElement("div");
div.style.width = "20%";
div.style.textAlign = "right";
div.style.display = "inline";
childDiv = elementId.getElementsByTagName('div')[0]
childDiv.style.display = "none";
elementId.appendChild(div, elementId );
div.innerHTML = '<button id="' + fieldId + '" type="button" style="margin-left: 4px; width: 50%;" >CRM Save Button</button>';
document.getElementById(atrname).style.width = "80%";
document.getElementById(fieldId ).onclick = function () { OnClickFunction(); };
}
}
function OnClickFunction() {
alert("clicked!");
}
随着涡轮形式的引入,情况发生了一些变化。如果要访问 DOM,请使用文档的父元素。
function createButton() {
var atrname = 'foobar';
if (window.parent.document.getElementById(atrname) != null) {
var fieldId = 'field' + atrname;
var elementId = window.parent.document.getElementById(atrname + '_d');
var div = window.parent.document.createElement('div');
div.style.width = '20%';
div.style.textAlign = 'right';
div.style.display = 'inline';
var childDiv = elementId.getElementsByTagName('div')[0];
childDiv.style.display = 'none';
elementId.appendChild(div, elementId);
div.innerHTML = '<button id="' + fieldId + '" type="button" style="margin-left: 4px; width: 50%;" >CRM Save Button</button>';
window.parent.document.getElementById(atrname).style.width = '80%';
window.parent.document.getElementById(fieldId).onclick = function () { OnClickFunction(); };
}
}