Kenneth Posted May 4, 2020 Share Posted May 4, 2020 Всем привет. Столкнулся с проблемой, в JS не силен, прошу помочь. Вот этот код работает: UniSession.AddJS('MainForm.UniEdit1.setValue("Test");'); А если хочу поменять в label, то не работает: UniSession.AddJS('MainForm.UniLabel1.setValue("Test");'); //Ошибка: "setValue is not a function" Что нужно использовать вместо SetValue, чтобы поменять текст в лейбле? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted May 4, 2020 Share Posted May 4, 2020 2 minutes ago, Kenneth said: А если хочу поменять в label, то не работает Привет, А что мешает если просто использовать?: UniLabel1.Text := 'Новое значение'; Quote Link to comment Share on other sites More sharing options...
Kenneth Posted May 4, 2020 Author Share Posted May 4, 2020 На самом деле у меня нет такого компонента на форме, это я просто для примера. Все находится в html и имеет свое id. Я нахожу по id и необходимо менять значение. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted May 4, 2020 Share Posted May 4, 2020 А какой у Вас html код? Quote Link to comment Share on other sites More sharing options...
Kenneth Posted May 4, 2020 Author Share Posted May 4, 2020 '<input class="align-text-bottom font-weight-bold" style="font-size:26px; margin:7px;" id="klv1">Старое значение</p>' procedure AjaxEvent(); UniSession.AddJS('document.getElementById("klv1").setValue("Новое значение");'); Quote Link to comment Share on other sites More sharing options...
Kenneth Posted May 4, 2020 Author Share Posted May 4, 2020 Ошибочка вышла.Вот: <p class="align-text-bottom font-weight-bold" style="font-size:26px; margin:7px;" id="klv'+IntToStr(Self.Tag)+'">1</p> Quote Link to comment Share on other sites More sharing options...
Kenneth Posted May 4, 2020 Author Share Posted May 4, 2020 <p class="align-text-bottom font-weight-bold" style="font-size:26px; margin:7px;" id="klv1">Старое значение</p> Вот так более читабельно будет. В общем в этом лейбле необходимо менять значение. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted May 4, 2020 Share Posted May 4, 2020 Используете UniHTMLFrame? Quote Link to comment Share on other sites More sharing options...
Kenneth Posted May 4, 2020 Author Share Posted May 4, 2020 нет. Испозльзую uniLabel.TextConversion:=txtHTML; Quote Link to comment Share on other sites More sharing options...
Sherzod Posted May 4, 2020 Share Posted May 4, 2020 Ок. Я проверю. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted May 4, 2020 Share Posted May 4, 2020 1 hour ago, Kenneth said: Испозльзую uniLabel.TextConversion:=txtHTML; Попробуйте, procedure TMainForm.UniButton4Click(Sender: TObject); begin UniLabel1.JSInterface.JSAssign('getEl().select("#klv1").elements[0].innerHTML', ['Новое значение']); end; Quote Link to comment Share on other sites More sharing options...
Kenneth Posted May 5, 2020 Author Share Posted May 5, 2020 @Sherzod спасибо большое, все работает! Я бы точно не догадался так сделать. Здесь мы присвоили значение, подскажите, а как получить значение из лейбла в переменную? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted May 5, 2020 Share Posted May 5, 2020 Вы же можете создать переменную и при вызове JS кода присвоить значение?.. Quote Link to comment Share on other sites More sharing options...
Kenneth Posted May 5, 2020 Author Share Posted May 5, 2020 @Sherzod а как тоже самое в мобильной версии сделать? Ваш пример для UnimLabel не работает. Вот такое сообщение выходит: "O61.GetEl is not a function"; Quote Link to comment Share on other sites More sharing options...
Sherzod Posted May 5, 2020 Share Posted May 5, 2020 Попробуйте element вместо getEl(). Quote Link to comment Share on other sites More sharing options...
Sherzod Posted May 5, 2020 Share Posted May 5, 2020 Получилось? Quote Link to comment Share on other sites More sharing options...
Kenneth Posted May 5, 2020 Author Share Posted May 5, 2020 Да спасибо. Сработало. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted May 5, 2020 Share Posted May 5, 2020 OK. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.