gpt4 book ai didi

javascript - 无法在使用 GAS 的 HTML 对话框中使用 Jquery UI 效果

转载 作者:行者123 更新时间:2023-12-03 07:07:54 27 4
gpt4 key购买 nike

我需要 Google Apps Script 的 HTML 对话框中的滚动效果。
https://docs.google.com/spreadsheets/d/1IHf2SkmoEyxDAs86FIdHWKfQ19i19-jUDFDlbMKJE8A/copy是我试过的,代码也是放在代码编辑器里的。
当高亮按钮被按下时,当 html 代码被放置在 HTML 对话框中时,它的高亮显示但不滚动。

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="//ssl.gstatic.com/docs/script/css/add-ons1.css">
<style>
.sidebar{padding:0}
.branding-below {
bottom: 80px;
top: 0;
}
</style>
<body>
<div class="sidebar branding-below" data-select2-id="58">
<div class="block">
<div id="main">
<button onclick="highlightSelect2('#sel3')" >Highlight sel3</button>
<button onclick="highlightSelect2('#sel5')">Highlight sel5</button>
<button onclick="highlightSelect2('#sel7')">Highlight sel7</button>
<br/>
<br/>
<table border="0" id="fields" style="padding:5px;width:100%;table-layout:fixed;">
<tr>
<tr>
<td class="gray" colspan="2">
<select class="field" style="width:50%" id="sel1">
<option>Example0 test</option>
<option>Beta test</option>
</select>
<br/>
<br/>
<br/>
<br/>
<br/>
</tr>
<tr>
<td class="gray" colspan="2">
<select class="field" style="width:50%" id="sel2">
<option>Example1 test</option>
<option>Beta test</option>
</select>
<br/>
<br/>
<br/>
<br/>
<br/>
</tr>
<tr>
<td class="gray" colspan="2">
<select class="field" style="width:50%" id="sel3">
<option>Example3 test</option>
<option>Beta test</option>
</select>
<br/>
<br/>
<br/>
<br/>
<br/>
</tr>
<tr>
<td class="gray" colspan="2">
<select class="field" style="width:50%" id="sel4">
<option>Alpha test</option>
<option>Beta test</option>
</select>
<br/>
<br/>
<br/>
<br/>
<br/>
</tr>
<tr>
<td class="gray" colspan="2">
<select class="field" style="width:50%" id="sel5">
<option>Alpha test</option>
<option>Beta test</option>
</select>
<br/>
<br/>
<br/>
<br/>
<br/>
</tr>
<tr>
<td class="gray" colspan="2">
<select class="field" style="width:50%" id="sel6">
<option>Alpha test</option>
<option>Beta test</option>
</select>
<br/>
<br/>
<br/>
<br/>
<br/>
</tr>
<tr>
<td class="gray" colspan="2">
<select class="field" style="width:50%" id="sel7">
<option>Alpha test</option>
<option>Beta test</option>
</select>
</tr>
</table>
<br/>
<br/>
<br/>
<br/>
<br/>
<button onclick="highlightSelect2('#sel3')" >Highlight sel3</button>
<button onclick="highlightSelect2('#sel5')">Highlight sel5</button>
<button onclick="highlightSelect2('#sel7')">Highlight sel7</button>
</div>
</div>
</div>
<div class="sidebar bottom">
<table width="100%" style="table-layout:fixed;">
<tbody>
<tr>
<td colspan="2" style="border-bottom:0px;" align="left">
<small align="center" id="status"></small>&emsp;
</td>
</tr>
<tr>
<td colspan="2" align="right">
<button id="reset">Reset</button>&nbsp;&nbsp;
</td>
</tr>
</tbody>
</table>
</div>
<script>
function highlightSelect2(selector) {
$(selector)
.next(".select2-container")
.find(".select2-selection")
.effect("highlight", {
color: "#f88"
}, 10000);

$('html, body').animate({
scrollTop: $(selector).offset().top
}, 1000);
}
$(document).ready(function () {
$('select').select2();
listen("select")

});

function listen(selector)
{
$(selector).on('change', function() {
alert("Cannot use this field as you have already used!");
highlightSelect2("#sel7")
$(this).val("");
});
}
</script>
</body>
</html>

enter image description here

最佳答案

您可以在 .sidebar 上添加动画

function highlightSelect2(selector) {
$(selector)
.next(".select2-container")
.find(".select2-selection")
.effect("highlight", {
color: "#f88"
}, 10000);
$('.sidebar').animate({
scrollTop: $(selector).offset().top
}, 1000);
}
$(document).ready(function() {
$('select').select2();
listen("select")

});

function listen(selector) {
$(selector).on('change', function() {
alert("Cannot use this field as you have already used!");
highlightSelect2("#sel7")
$(this).val("");
});
}
.sidebar {
padding: 0
}

.branding-below {
bottom: 80px;
top: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="//ssl.gstatic.com/docs/script/css/add-ons1.css">
<div class="sidebar branding-below" data-select2-id="58">
<div class="block">
<div id="main">
<button onclick="highlightSelect2('#sel3')">Highlight sel3</button>
<button onclick="highlightSelect2('#sel5')">Highlight sel5</button>
<button onclick="highlightSelect2('#sel7')">Highlight sel7</button>
<br />
<br />
<table border="0" id="fields" style="padding:5px;width:100%;table-layout:fixed;">
<tr>
<tr>
<td class="gray" colspan="2">
<select class="field" style="width:50%" id="sel1">
<option>Example0 test</option>
<option>Beta test</option>
</select>
<br />
<br />
<br />
<br />
<br />
</tr>
<tr>
<td class="gray" colspan="2">
<select class="field" style="width:50%" id="sel2">
<option>Example1 test</option>
<option>Beta test</option>
</select>
<br />
<br />
<br />
<br />
<br />
</tr>
<tr>
<td class="gray" colspan="2">
<select class="field" style="width:50%" id="sel3">
<option>Example3 test</option>
<option>Beta test</option>
</select>
<br />
<br />
<br />
<br />
<br />
</tr>
<tr>
<td class="gray" colspan="2">
<select class="field" style="width:50%" id="sel4">
<option>Alpha test</option>
<option>Beta test</option>
</select>
<br />
<br />
<br />
<br />
<br />
</tr>
<tr>
<td class="gray" colspan="2">
<select class="field" style="width:50%" id="sel5">
<option>Alpha test</option>
<option>Beta test</option>
</select>
<br />
<br />
<br />
<br />
<br />
</tr>
<tr>
<td class="gray" colspan="2">
<select class="field" style="width:50%" id="sel6">
<option>Alpha test</option>
<option>Beta test</option>
</select>
<br />
<br />
<br />
<br />
<br />
</tr>
<tr>
<td class="gray" colspan="2">
<select class="field" style="width:50%" id="sel7">
<option>Alpha test</option>
<option>Beta test</option>
</select>
</tr>
</table>
<br />
<br />
<br />
<br />
<br />
<button onclick="highlightSelect2('#sel3')">Highlight sel3</button>
<button onclick="highlightSelect2('#sel5')">Highlight sel5</button>
<button onclick="highlightSelect2('#sel7')">Highlight sel7</button>
</div>
</div>
</div>
<div class="sidebar bottom">
<table width="100%" style="table-layout:fixed;">
<tbody>
<tr>
<td colspan="2" style="border-bottom:0px;" align="left">
<small align="center" id="status"></small>&emsp;
</td>
</tr>
<tr>
<td colspan="2" align="right">
<button id="reset">Reset</button>&nbsp;&nbsp;
</td>
</tr>
</tbody>
</table>
</div>

关于javascript - 无法在使用 GAS 的 HTML 对话框中使用 Jquery UI 效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64206206/

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